home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / science / ack3d.zip / ACKLDBMP.C < prev    next >
Text File  |  1994-01-09  |  6KB  |  210 lines

  1. /******************* ( Animation Construction Kit 3D ) ***********************/
  2. /*              Load Bitmap Routines                     */
  3. /* CopyRight (c) 1993       Author: Lary Myers                     */
  4. /*****************************************************************************/
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <dos.h>
  9. #include <mem.h>
  10. #include <alloc.h>
  11. #include <io.h>
  12. #include <fcntl.h>
  13. #include <time.h>
  14. #include <string.h>
  15. #include <sys\stat.h>
  16. #include "ack3d.h"
  17. #include "ackeng.h"
  18. #include "ackext.h"
  19. #include "xmslib.h"
  20.  
  21. char *GetExtent(char *s);
  22. UCHAR far *AckReadiff(char *s);
  23.  
  24. /****************************************************************************
  25. ** The application should call this routine to load a bitmap into either   **
  26. ** real or XMS memory.                               **
  27. **                                       **
  28. ** BitmapNumber is the index number to place the file into.           **
  29. ** BitmapType is either TYPE_WALL or TYPE_OBJECT               **
  30. ** BitmapName is the filename of the bitmap to load.               **
  31. **                                       **
  32. ** Bitmaps used by the ACK engine are 64x64 in size and may be either raw  **
  33. ** image (.IMG) files or Deluxe Paint brushes (.BBM) files.           **
  34. **                                       **
  35. ****************************************************************************/
  36. int AckLoadBitmap(ACKENG *ae,int BitmapNumber,int BitmapType,char *BitmapName)
  37. {
  38.     int        handle,bFlag;
  39.     int        x,y;
  40.     int        sPos,dPos;
  41.     unsigned char ch;
  42.     XMSHANDLE      xPtr;
  43.     UCHAR    far  *buf;
  44.     UCHAR    far  *bmp;
  45.  
  46. bFlag = 0;
  47.  
  48. if (!(stricmp(GetExtent(BitmapName),"BBM")))
  49.     {
  50.     buf = AckReadiff(BitmapName);
  51.     if (buf == NULL)
  52.     return(ERR_LOADINGBITMAP);
  53.  
  54.     memmove(buf,&buf[4],BITMAP_SIZE);
  55.     bFlag = 1;
  56.     }
  57. else
  58.     {
  59.     buf = malloc(BITMAP_SIZE);
  60.     if (buf == NULL)
  61.     return(ERR_NOMEMORY);
  62.     }
  63.  
  64. bmp = malloc(BITMAP_SIZE);
  65. if (bmp == NULL)
  66.     {
  67.     free(buf);
  68.     return(ERR_NOMEMORY);
  69.     }
  70.  
  71. if (BitmapType == TYPE_WALL)
  72.     ae->bMaps[BitmapNumber] = bmp;
  73.  
  74. if (BitmapType == TYPE_OBJECT)
  75.     ae->oMaps[BitmapNumber] = bmp;
  76.  
  77. if (!bFlag)
  78.     {
  79.     handle = open(BitmapName,O_RDWR|O_BINARY);
  80.     if (handle < 1)
  81.     {
  82.     free(buf);
  83.     free(bmp);
  84.     return(ERR_BADFILE);
  85.     }
  86.  
  87.     read(handle,buf,4);        /* Skip width and height for now */
  88.     read(handle,buf,BITMAP_SIZE);
  89.     close(handle);
  90.     }
  91.  
  92. for (y = 0; y < BITMAP_HEIGHT; y++)
  93.     {
  94.     sPos = y;
  95.     dPos = y * BITMAP_WIDTH;
  96.     for (x = 0; x < BITMAP_WIDTH; x++)
  97.     {
  98.     ch = buf[sPos];
  99.     bmp[dPos++] = ch;
  100.     sPos += BITMAP_WIDTH;
  101.     }
  102.     }
  103.  
  104. #if USE_XMS
  105.     if (UseXMS > 0)
  106.     {
  107.     xPtr = XMSalloc(BITMAP_SIZE);
  108.     if (xPtr != XMSHNULL)
  109.         {
  110.         if (BitmapType == TYPE_WALL)
  111.         ae->bMaps[BitmapNumber] = (UCHAR far *)xPtr;
  112.         else
  113.         ae->oMaps[BitmapNumber] = (UCHAR far *)xPtr;
  114.  
  115.         XMSput(xPtr,bmp,BITMAP_SIZE);
  116.         free(bmp);
  117.         }
  118.     }
  119. #endif
  120.  
  121. free(buf);
  122. return(0);
  123. }
  124.  
  125. /****************************************************************************
  126. ** Internal routine to get the file extent from a filename.           **
  127. **                                       **
  128. ****************************************************************************/
  129. char *GetExtent(char *s)
  130. {
  131.     char    *e;
  132.  
  133. e = strchr(s,'.');
  134. if (e == NULL)
  135.     return(s);
  136. e++;
  137.  
  138. return(e);
  139. }
  140.  
  141.  
  142. /****************************************************************************
  143. ** Simplified call to load a wall bitmap.                   **
  144. **                                       **
  145. ****************************************************************************/
  146. int AckLoadWall(ACKENG *ae,int WallNumber,char *bmFileName)
  147. {
  148.  
  149. return( AckLoadBitmap(ae,WallNumber,TYPE_WALL,bmFileName) );
  150. }
  151.  
  152.  
  153. /****************************************************************************
  154. ** Simplified call to load an object bitmap.                   **
  155. **                                       **
  156. ****************************************************************************/
  157. int AckLoadObject(ACKENG *ae,int BmpNumber,char *bmFileName)
  158. {
  159.  
  160. return( AckLoadBitmap(ae,BmpNumber,TYPE_OBJECT,bmFileName) );
  161. }
  162.  
  163.  
  164. /****************************************************************************
  165. ** The application should make this call to perform the necessary setup on **
  166. ** an object.                                   **
  167. **                                       **
  168. ** ObjNumber is the object index                       **
  169. ** NumBitmaps is the total number of bitmaps that the object has (min 1).  **
  170. ** bmNums is a char array of the bitmap numbers the object uses.       **
  171. **                                       **
  172. ** If an object has more than 1 bitmap and the OF_ANIMATE flag is NOT set  **
  173. ** then it is assumed the object has more than one side and will be seen   **
  174. ** from various angles. If the OF_ANIMATE flag IS set then the object will **
  175. ** animate through the multiple bitmaps in the supplied list.           **
  176. **                                       **
  177. ****************************************************************************/
  178. int AckCreateObject(ACKENG *ae,int ObjNumber,int NumBitmaps,UCHAR *bmNums)
  179. {
  180.     int        i;
  181.  
  182.  
  183. if (NumBitmaps >= MAX_VIEWS)
  184.     return(ERR_TOMANYVIEWS);
  185.  
  186. if (!NumBitmaps)    /* Force to at least one bitmap */
  187.     NumBitmaps++;
  188.  
  189. /* Setup index to which bitmap is displayed */
  190. ae->ObjList[ObjNumber].CurNum = 0;
  191. ae->ObjList[ObjNumber].MaxNum = NumBitmaps - 1;
  192.  
  193. /* Keep the maximum number current */
  194. if (ObjNumber >= ae->MaxObjects && ObjNumber < MAX_OBJECTS)
  195.     ae->MaxObjects = ObjNumber + 1;
  196.  
  197. /* Calculate sides if a multi-sided object */
  198. ae->ObjList[ObjNumber].Sides = 0;
  199. if (NumBitmaps > 1 && !(ae->ObjList[ObjNumber].Flags & OF_ANIMATE))
  200.     ae->ObjList[ObjNumber].Sides = INT_ANGLE_360 / NumBitmaps;
  201.  
  202. /* Transfer bitmap numbers to object structure */
  203. for (i = 0; i < NumBitmaps; i++)
  204.     ae->ObjList[ObjNumber].bmNum[i] = bmNums[i];
  205.  
  206.  
  207. return(0);
  208. }
  209.  
  210.